//
//  NSObject+Orientation.m
//  CircleBaby
//
//  Created by Du Kai on 2016/10/31.
//  Copyright © 2016年 TimeFace. All rights reserved.
//

#import "NSObject+Orientation.h"
#import <UIKit/UIKit.h>

@implementation NSObject (Orientation)

- (NSInteger)iosOrientationToExifOrientation:(UIImageOrientation)imageOrientation {
    NSInteger standardOrientation = 0;
    switch (imageOrientation) {
        case UIImageOrientationUp: {
            standardOrientation = 1;
            break;
        }
        case UIImageOrientationDown: {
            standardOrientation = 3;
            break;
        }
        case UIImageOrientationLeft: {
            standardOrientation = 8;
            break;
        }
        case UIImageOrientationRight: {
            standardOrientation = 6;
            break;
        }
        case UIImageOrientationUpMirrored: {
            standardOrientation = 2;
            break;
        }
        case UIImageOrientationDownMirrored: {
            standardOrientation = 4;
            break;
        }
        case UIImageOrientationLeftMirrored: {
            standardOrientation = 5;
            break;
        }
        case UIImageOrientationRightMirrored: {
            standardOrientation = 7;
            break;
        }
        default:
            break;
    }
    return standardOrientation;
}

- (UIImageOrientation)exifOrientationToIOSOrientation:(NSInteger)orientation {
    UIImageOrientation imageOrientation = UIImageOrientationUp;
    switch (orientation) {
        case 1: {
            imageOrientation = UIImageOrientationUp;
            break;
        }
        case 2: {
            imageOrientation = UIImageOrientationUpMirrored;
            break;
        }
        case 3: {
            imageOrientation = UIImageOrientationDown;
            break;
        }
        case 4: {
            imageOrientation = UIImageOrientationDownMirrored;
            break;
        }
        case 5: {
            imageOrientation = UIImageOrientationLeftMirrored;
            break;
        }
        case 6: {
            imageOrientation = UIImageOrientationRight;
            break;
        }
        case 7: {
            imageOrientation = UIImageOrientationRightMirrored;
            break;
        }
        case 8: {
            imageOrientation = UIImageOrientationLeft;
            break;
        }
        default:
            break;
    }
    return imageOrientation;
}

@end
